//
//  TOradioDetailHeader.m
//  B段项目
//
//  Created by dllo on 15/12/26.
//  Copyright © 2015年 张智超. All rights reserved.
//

#import "TOradioDetailHeader.h"

@interface TOradioDetailHeader ()

@property (nonatomic, strong)UIImageView *headImageView;
@property (nonatomic, strong)UIImageView *iconImageView;
@property (nonatomic, strong)UILabel *nameLabel;
@property (nonatomic, strong)UILabel *contentLabel;
@property (nonatomic, strong)UIImageView *playImageView;
@property (nonatomic, strong)UILabel *playCountLabel;

@end

@implementation TOradioDetailHeader

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self createSubview];
    }
    
    return self;
}

-(instancetype)init
{
    self = [super init];
    if (self) {
        
        [self createSubview];
    }
    
    return self;
}

-(void)createSubview
{
    UIView *nilView = [[UIView alloc] initWithFrame:CGRectMake(0, self.frame.size.height - 1, WIDTH, 1)];
    nilView.backgroundColor = [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1];
    [self addSubview:nilView];
    
    
    
    self.headImageView = [[UIImageView alloc] init];
        self.headImageView.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.headImageView];
    
    [self.headImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.top.right.equalTo(self);
        make.height.mas_equalTo(self).multipliedBy(0.6);
    }];

    self.iconImageView = [[UIImageView alloc] init];
        self.iconImageView.backgroundColor = [UIColor clearColor];
   
    self.iconImageView.layer.borderColor = [UIColor whiteColor].CGColor;
    [self addSubview:self.iconImageView];
    [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.headImageView.mas_bottom).offset(20);
        make.left.mas_equalTo(self).offset(30);
        make.width.height.mas_equalTo(self.headImageView.mas_height).multipliedBy(0.2);
        
    }];
    
    self.iconImageView.layer.masksToBounds = YES;
    self.iconImageView.layer.cornerRadius = HEIGHT*0.4*0.6*0.2*0.5;
    self.iconImageView.layer.borderWidth = 0;
    
    
    self.nameLabel = [[UILabel alloc] init];
    self.nameLabel.textColor = [UIColor colorWithRed:0.49 green:0.57 blue:0.67 alpha:1];
    self.nameLabel.font = [UIFont systemFontOfSize:14];
    [self addSubview:self.nameLabel];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(self.iconImageView.mas_right).offset(10);
        make.width.mas_equalTo(self).multipliedBy(0.3);
        make.top.bottom.mas_equalTo(self.iconImageView);
    }];
    
    
    self.playCountLabel = [[UILabel alloc] init];
    self.playCountLabel.backgroundColor = [UIColor clearColor];
    self.playCountLabel.textColor = [UIColor colorWithRed:0.82 green:0.82 blue:0.82 alpha:1];
    //        self.playCountLabel.textAlignment = NSTextAlignmentRight;
    self.playCountLabel.font = [UIFont systemFontOfSize:11];
    [self addSubview:self.playCountLabel];
    
    [self.playCountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.height.equalTo(self.iconImageView);
        make.right.mas_equalTo(self).offset(-10);
        make.width.mas_equalTo(self.nameLabel).multipliedBy(0.5);
    }];
    
    self.playImageView = [[UIImageView alloc] init];
    [self addSubview:self.playImageView];
    self.playImageView.image = [UIImage imageNamed:@"bofang.png"];
    self.playImageView.contentMode = UIViewContentModeScaleAspectFit;
    [self.playImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.equalTo(self.iconImageView);
        make.right.mas_equalTo(self.playCountLabel.mas_left).offset(-5);
        make.width.height.mas_equalTo(self.iconImageView).multipliedBy(0.6);
    }];
    
    
    
    
    
    self.contentLabel = [[UILabel alloc] init];
    self.contentLabel.backgroundColor = [UIColor clearColor];
    self.contentLabel.textColor = [UIColor colorWithRed:0.45 green:0.45 blue:0.45 alpha:1];
    self.contentLabel.font = [UIFont systemFontOfSize:14];
    [self addSubview:self.contentLabel];
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.height.mas_equalTo(self.iconImageView);
        make.top.mas_equalTo(self.iconImageView.mas_bottom).offset(15);
        make.right.mas_equalTo(self).offset(-10);
        
    }];
}

-(void)setRadioInfo:(TORadioModel *)radioInfo
{
    _radioInfo = radioInfo;
    
    [self.headImageView sd_setImageWithURL:self.radioInfo.coverimg placeholderImage:nil];
    [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:self.radioInfo.icon] placeholderImage:nil];
    self.nameLabel.text = self.radioInfo.uname ;
    self.contentLabel.text = self.radioInfo.desc;
    self.playCountLabel.text = [NSString stringWithFormat:@"%@", self.radioInfo.musicvisitnum];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
